clear
clear mata
clear matrix

cd ..                                                                            /* Goes back to parent folder */

capture log close
log using "log\14_Frontier.log", replace

*       Patriotism!

*       FIRST VERSION  June       7, 2022
*       THIS VERSION   June       7, 2022
*       LAST RUN       June       7, 2022

*       LAST REVISOR		LMC

*       Log of revisions:

*       This prepares frontier data

********************************************************************************
****                      PLAN OF THE PROCEDURE                             ****
****  1. Creating Frontier Dataset                                          ****
****  2. Final Merge w/ Bridge		                                        ****
****                                                                        ****
********************************************************************************

********************************************************************************
****  1. Creating Frontier Dataset                                          ****
********************************************************************************
do "code-build/01_Shopping_List.do"

use "rawdata/Frontier_Culture/names1940.dta", replace

rename gisjoin GISJOIN

replace GISJOIN = "G1200250" if GISJOIN == "G1200860" /*Change Miami-Dade, FL's county GISJOIN in order to be mergeable with Dade, FL */
replace GISJOIN = "G3200250" if GISJOIN == "G3205100" /*Change Carson City, NV 's county GISJOIN in order to be mergeable with Ormsby, NV */
replace GISJOIN = "G5101510" if GISJOIN == "G5108100" /*Change Virginia Beach city, VI's county GISJOIN in order to be mergeable with Elizabeth City, VI */

replace GISJOIN = "G0400270" if GISJOIN == "G0400120" /* La Paz, AZ formed from Yuma county in 1983 */
replace GISJOIN = "G0800130" if GISJOIN == "G0800140" /* Broomfield, CO incorporated in 1961 from Boulder county */
replace GISJOIN = "G3500610" if GISJOIN == "G3500060" /* Cibola, NM formed in 1981 from Valencia */
replace GISJOIN = "G5100190" if GISJOIN == "G5105150" /* Bedford City, VA became independent city in 1968, before it was in Bedford county */
replace GISJOIN = "G5107805" if GISJOIN == "G5105500" /* Chesapeake city was formed in 1963 when South Norfolk consolidated with North Norfolk. N+S Norfolk are all 1 county in the ND database */
replace GISJOIN = "G5100410" if GISJOIN == "G5105700" /* Colonial Heights City, VA incorporated as a city in 1948, separating from Chesterfield county */
replace GISJOIN = "G5100050" if GISJOIN == "G5105800" /* Covington City, VA is surrounded by Alleghany and "The Bureau of Economic Analysis combines the city of Covington with Alleghany county for statistical purposes." */
replace GISJOIN = "G5100810" if GISJOIN == "G5105950" /* Emporia City VA is surrounded by Greensville County The Bureau of Economic Analysis combines the city of Emporia with surrounding Greensville county for statistical purposes.  */
replace GISJOIN = "G5100590" if GISJOIN == "G5106000" /* Fairfax City, VA is an enclave surrounded by the separate political entity Fairfax County. */
replace GISJOIN = "G5100590" if GISJOIN == "G5106100" /* For statistical purposes, the U.S. Department of Commerce's Bureau of Economic Analysis combines the City of Falls Church with Fairfax City and Fairfax County.  */
replace GISJOIN = "G5101750" if GISJOIN == "G5106200" /* The Bureau of Economic Analysis combines the city of Franklin with Southampton County for statistical purposes.  */
replace GISJOIN = "G5100350" if GISJOIN == "G5106400" /* The Bureau of Economic Analysis combines the city of Galax with neighboring Carroll County for statistical purposes. */
replace GISJOIN = "G5101630" if GISJOIN == "G5106780" /* The Bureau of Economic Analysis combines the city of Lexington with Rockbridge County for statistical purposes.  */
replace GISJOIN = "G5101530" if GISJOIN == "G5106830" /* The Bureau of Economic Analysis includes both Manassas and Manassas Park with Prince William County for statistical purposes.  */ 
replace GISJOIN = "G5101530" if GISJOIN == "G5106850" /* The Bureau of Economic Analysis includes both Manassas and Manassas Park with Prince William County for statistical purposes.  */ 
replace GISJOIN = "G5101950" if GISJOIN == "G5107200" /* The Bureau of Economic Analysis combines the city of Norton with surrounding Wise County for statistical purposes.  */
replace GISJOIN = "G5101990" if GISJOIN == "G5107350" /* The Bureau of Economic Analysis combines the city of Poquoson with surrounding York County for statistical purposes.  */
replace GISJOIN = "G5101610" if GISJOIN == "G5107750" /* The Bureau of Economic Analysis combines the city of Salem with Roanoke County, which surrounds both Salem and the neighboring City of Roanoke, for statistical purposes.  */
replace GISJOIN = "G5100150" if GISJOIN == "G5108200" /* Waynesboro city, VA incorporated from Augusta county in 1948 */
replace GISJOIN = "G5501150" if GISJOIN == "G5500780" /* The county was created from the northeastern portion of 7 townships of Shawano County and the Western 3 townships of Oconto County on July 3, 1959. We assign it to Shawano */


********************************************************************************
****  2. Final Merge w/ Bridge		                                        ****
********************************************************************************
merge m:1 GISJOIN using "rawdata/maps/Bridge.dta" 
/* List of non-matched observations:
G3500280    maser only (1)       Los Alamos was administered directly by US Govt until 1949. Not matched 
G1300395	using only (2)		 Campbell (Fulton/Campbell/Milton), Fulton is merged. Go Ahead!
G1302015	using only (2)		 Milton (Fulton/Campbell/Milton), Fulton is merged. Go Ahead!
G3001130	using only (2)		 Yellowstone National Park (Yellowstone National Park), (No Unmatched in Montana, stays nonmerged)
G4600010	using only (2)		 Armstrong (Armstrong), (No Unmatched in South Dakota, stays nonmerged)
G4601310	using only (2)		 Washabaugh (Washabaugh), (No Unmatched in South Dakota, stays nonmerged)
G4601330	using only (2)	     Washington (Washington), (No Unmatched in South Dakota, stays nonmerged)
G5100550	using only (2)		 Elizabeth City (Elizabeth City Co/Hamp), Hampton is merged. Go Ahead!
G5101230	using only (2)		 Nansemond (Nansemond Co/Suffolk), Suffolk is merged. Go Ahead!
G5101290	using only (2)		 Norfolk (Norfolk Co/3 cities), Norfolk City is merged. Go Ahead!
G5101890	using only (2)		 Warwick (Warwick/Newport News), Newport News is merged. Go Ahead!
G5105600	using only (2)		 Clifton Forge (Allegany Co/Clifton Fo), Alleghany is merged. Go Ahead!
G5600470	using only (2)		 Yellowstone (Yellowstone), (No Unmatched in Wyoming, stays nonmerged)
*/

rename countynamend countyname
order state stateicpsr countynd countyname

drop if state == ""

collapse (min) tye_tfe890_500k_100_l6, by(stateicpsr countynd countyname)
replace countyname = "Yellowstone"  if countyname == "Yellowstone " & stateicpsr == 68

lab var tye_tfe890_500k_100_l6  "Frontier Experience (Bazzi et al. 2020)"

save "data\frontier.dta", replace

log close
exit